package com.xm.design_patterns;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Author：xm
 * Project：interview
 * Date：2025/7/31  0:54
 */

public class _02_Singleton_LazyTestThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        System.out.println("懒汉：");

        Thread task = new Thread(new Runnable() {
            @Override
            public void run() {
                // System.out.println(Thread.currentThread().getName());
                _02_Singleton_Lazy lazy = _02_Singleton_Lazy.getInstance();
                // try {
                //     Thread.sleep(5000);
                // } catch (InterruptedException e) {
                //     throw new RuntimeException(e);
                // }
                // _02_Singleton_Lazy lazy2 = _02_Singleton_Lazy.getInstance();
                // System.out.println("同一个对象：" + (lazy == lazy2));
            }
        });

        Thread task2 = new Thread(new Runnable() {
            @Override
            public void run() {
                // System.out.println(Thread.currentThread().getName());
                _02_Singleton_Lazy lazy = _02_Singleton_Lazy.getInstance();
                // try {
                //     Thread.sleep(5000);
                // } catch (InterruptedException e) {
                //     throw new RuntimeException(e);
                // }
                // _02_Singleton_Lazy lazy2 = _02_Singleton_Lazy.getInstance();
                // System.out.println("同一个对象：" + (lazy == lazy2));
            }
        });
        // for (int i = 0; i < 2; i++) {
            // System.out.println(Instant.now());
            // System.out.println(Thread.currentThread().getName());
            // executorService.execute(task);
        // }
        executorService.execute(task);
        executorService.execute(task2);
        executorService.shutdown();
    }
}
